export SRCS_SERVER = server.c mutexqueue.c mutexfile.c filemanagement.c socketfile.c mutexlist.c
export SRCS_TOOLS_SERVER = list.c intlist.c charlist.c toolsclientserver.c
export SRCS_CLIENT = client.c socketfilepair.c
export SRCS_TOOLS_CLIENT = toolsstring.c list.c charlist.c toolsclientserver.c pthreadlist.c
export SRCS_GTK = zmenu.c zcontainer.c zfile.c zserver.c

SRC_SERVER = main.c
SRC_CLIENT = mainclient.c
SRC_GTK = maingtk.c

export CC = gcc
export CFLAGS = -W -Wall -pedantic -ggdb -g -O3 `pkg-config --cflags glib-2.0` 
export LDFLAGS = -pthread `pkg-config --libs glib-2.0` 
export CFLAGSGTK = $(CFLAGS) `pkg-config --cflags gtk+-3.0`
LDFLAGSGTK = $(LDFLAGS) `pkg-config --libs gtk+-3.0`

export OBJ_DIR=obj

export BIN_DIR=bin
SRC_DIR=src
export SRC_DIR_SERVER=server
export SRC_DIR_CLIENT=client
export SRC_DIR_GTK=gtk
export SRC_DIR_TOOLS=tools

FINAL_TARGET_SERVER=server
FINAL_TARGET_CLIENT=client
FINAL_TARGET_GTK=gclient

OBJS_SERVER = $(SRCS_SERVER:%.c=$(OBJ_DIR)/%.o)
OBJS_CLIENT = $(SRCS_CLIENT:%.c=$(OBJ_DIR)/%.o)
OBJS_GTK = $(SRCS_GTK:%.c=$(OBJ_DIR)/%.o)
OBJS_TOOLS_SERVER = $(SRCS_TOOLS_SERVER:%.c=$(OBJ_DIR)/%.o)
OBJS_TOOLS_CLIENT = $(SRCS_TOOLS_CLIENT:%.c=$(OBJ_DIR)/%.o)

all: server client 

server:
	(cd $(SRC_DIR) && make server)
	$(CC) $(CFLAGS) $(SRC_DIR)/$(SRC_DIR_SERVER)/$(SRC_SERVER) $(OBJS_SERVER) $(OBJS_TOOLS_SERVER) -o $(BIN_DIR)/$(FINAL_TARGET_SERVER) $(LDFLAGS)

client:
	(cd $(SRC_DIR) && make client)
	$(CC) $(CFLAGS) $(SRC_DIR)/$(SRC_DIR_CLIENT)/$(SRC_CLIENT) $(OBJS_CLIENT) $(OBJS_TOOLS_CLIENT) -o $(BIN_DIR)/$(FINAL_TARGET_CLIENT) $(LDFLAGS)

gtk:
	(cd $(SRC_DIR) && make gtk)
	$(CC) $(CFLAGSGTK) $(SRC_DIR)/$(SRC_DIR_GTK)/$(SRC_GTK) $(OBJS_GTK) $(OBJS_CLIENT) $(OBJS_TOOLS_CLIENT) -o $(BIN_DIR)/$(FINAL_TARGET_GTK) $(LDFLAGSGTK)

clean:
	rm -f $(OBJ_DIR)/*.o $(BIN_DIR)/$(FINAL_TARGET_SERVER) $(BIN_DIR)/$(FINAL_TARGET_CLIENT) $(BIN_DIR)/$(FINAL_TARGET_GTK)
